using System;
using System.Text;
using NovaCore.Interop;
using NovaCore.Properties;

namespace NovaCore {
	public static class NovaCoreSdk {
		private static string _version;
		public static string Version {
			get {
				if (_version == null) {
					byte[] buffer = new byte[10];
					Core.NvtlCommon_GetSdkVersion(buffer, 10);
					_version = Encoding.ASCII.GetString(buffer);
				}

				return _version;
			}
		}

		public static bool Failed(NvtlErrorCode result) {
			return !Succeeded(result);
		}

		public static bool Succeeded(NvtlErrorCode result) {
			return result == NvtlErrorCode.LR_ERROR_SUCCESS;
		}

		public static void ThrowOnFailure(NvtlErrorCode result) {
			if (Failed(result)) {
				string errorName = Enum.GetName(typeof(NvtlErrorCode), result);
				string errorMessage = Resources.ResourceManager.GetString(errorName);
				throw new NovaCoreException(errorMessage, result);
			}
		}
	}
}